package com.neusoft.neuiotms.dcom.converter.problem;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.neusoft.bizcore.web.dto.AbstractConverter;
import com.neusoft.neuiotms.dcom.dto.problem.ProblemHandlingAttachmentDTO;
import com.neusoft.neuiotms.dcom.model.problem.ProblemHandlingAttachment;
import com.neusoft.neuiotms.dcom.repository.problem.ProblemHandlingAttachmentRepository;

@Component
public class ProblemHandlingAttachmentConverter
        extends AbstractConverter<ProblemHandlingAttachment, ProblemHandlingAttachmentDTO> {

    @Autowired
    private ProblemHandlingAttachmentRepository incidentHandleAttachmentRepository;

    @Override
    public ProblemHandlingAttachment toModel(final ProblemHandlingAttachmentDTO dto) {
        ProblemHandlingAttachment model;
        if (dto.isNew()) {
            model = new ProblemHandlingAttachment();
        } else {
            model = this.incidentHandleAttachmentRepository.getOne(dto.getId());
        }
        model.setFsId(dto.getFsId());
        model.setName(dto.getName());
        return model;
    }

    @Override
    public ProblemHandlingAttachmentDTO toDTO(final ProblemHandlingAttachment model, final boolean forListView) {
        final ProblemHandlingAttachmentDTO dto = new ProblemHandlingAttachmentDTO();
        dto.setFsId(model.getFsId());
        dto.setId(model.getId());
        dto.setName(model.getName());
        return dto;
    }
}
